package com.rbs.controller;

import com.rbs.entity.User;
import com.rbs.service.Impl.UserServiceImpl;
import com.rbs.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(urlPatterns = "/login")
public class LoginController extends HttpServlet {
    private UserService userService = new UserServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收客户端请求参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        User user = userService.login(username,password);
        if (user != null){
            request.getSession().setAttribute("user",user);
            response.sendRedirect(request.getContextPath()+"/selectByPageController");
        }else {
            response.sendRedirect(request.getContextPath()+"/Login.jsp");
        }
    }
}
